﻿@{
    ViewBag.Title = "BatchSet";
}
@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>
    <style>
        .setDiv{
            width:100%;
            height:100%;
        }
    </style>
}

<div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;">
    <table style="width:100%;">
        <tr>
            <td style="width:100%;">
                <a class="mini-button" id="save" name="save" iconCls="icon-save" onclick="saveas" plain="true">确定</a>
                <a class="mini-button" id="close" name="close" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
            </td>
        </tr>
    </table>
</div>

<div style="width:200px;float:left;height:100%;">
    <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;"
            borderStyle="border:1;" url="" showPager="false"
            allowCellSelect="true" allowCellEdit="false" showColumnsMenu="true" fitColumns="false"
            sortMode="client" onselectionchanged="SelectionChanged">
        <div property="columns">
            <div type="checkcolumn"></div>
            <div field="text" name="text" width="170" headeralign="center" allowsort="true">设置项目</div>
        </div>
    </div>
</div>
<div style="width:400px;float:left;">
    <div class="setDiv fit">
        <div id="BA1" class="setDiv">
            <table style="width:100%;margin-top:10px">
                <tr>
                    <td width="80px" height="32px" align="right">提成系数：</td>
                    <td width="200px" height="32px">
                        <input name="FRebateAmt" class="mini-spinner" minValue="0" maxValue="99999999" changeOnMousewheel="false" value="0"
                               style="width: 70px;" TabIndex="1005" showbutton="false" format="#,0.00" align="right" selectOnFocus="true" />
                        <input id="FRebateID" name="FRebateID" class="mini-combobox" style="width:122px;margin-left:0px;" showNullItem="false"
                               allowInput="false" align="left" value="1" data="comPoolAgio" />
                    </td>
                </tr>
            </table>
        </div>
        <div id="BA2" class="setDiv">
            <table style="width:100%;margin-top:10px">
                <tr>
                    <td width="80px" height="32px" align="right">
                        商品分类：
                    </td>
                    <td width="200px" height="32px">
                        @Html.Partial("~/Views/Modular/LookupGoodsClass.cshtml")
                    </td>
                </tr>
            </table>
        </div>
        <div id="BA4" class="setDiv">
            <table style="width:100%;margin-top:10px">
                <tr>
                    <td width="80px" height="32px" align="right">会员积分：</td>
                    <td width="200px" height="32px">
                        <input id="FPoint" name="FPoint" class="mini-spinner " style="width:70px;" minValue="-9999999" maxValue="99999999" value="0" TabIndex="11" showbutton="false" format="#,0.00" />
                        <input id="FPointType" name="FPointType" class="mini-combobox" style="width:125px;margin-left:0px;" showNullItem="false"
                                allowInput="false" align="left" value="0" data="comPointType" />
                    </td>
                </tr>
            </table>
        </div>
        <div id="BA5" class="setDiv">
            <table style="width:100%;margin-top:10px">
                <tr>
                    <td width="80px" height="32px" align="right">组织机构：</td>
                    <td width="200px" height="32px">
                        @Html.Partial("~/Views/Modular/LookupPriceBook.cshtml")
                    </td>
                </tr>
            </table>
        </div>
        <div id="BA6" class="setDiv">
            <table style="width:100%;margin-top:10px">
                <tr>
                    <td width="80px" height="32px" align="right">商品品牌：</td>
                    <td width="200px" height="32px">
                        @Html.Partial("~/Views/Modular/LookupGoodsBrand.cshtml")
                    </td>
                </tr>
            </table>
        </div>
        <div id="BA7" class="setDiv">
            <table style="width: 100%; margin-top: 10px">
                <tr>
                    <td width="80px" height="32px" align="right">最抵折扣：</td>
                    <td width="200px" height="32px">
                        <input id="FLowestDis" name="FLowestDis" class="mini-spinner " style="width: 115px;" minValue="0" maxValue="1" value="0" TabIndex="11" showbutton="false" format="#,0.00"/>
                    </td>
                </tr>
            </table>
        </div>
        <div id="BA8" class="setDiv">
            <table style="width:100%;margin-top:10px">
                <tr>
                    <td width="80px" height="32px" align="right">返利：</td>
                    <td width="200px" height="32px">
                        <input name="rebateValue" class="mini-spinner" minValue="0" maxValue="99999999" changeOnMousewheel="false" value="0"
                               style="width: 70px;" TabIndex="1005" showbutton="false" format="#,0.00" align="right" selectOnFocus="true" />
                        <input id="rebateType" name="rebateType" class="mini-combobox" style="width: 122px; margin-left: 0px;" showNullItem="false"
                               allowInput="false" align="left" value="0" data="rebateType"/>
                        <span style="color: red;">如果选择按百分比默认带%符号,填10就是10%</span>
                    </td>
                </tr>
            </table>
        </div>
        <div id="BA9" class="setDiv">
            <table style="width: 100%; margin-top: 10px">
                <tr>
                    <td width="80px" height="32px" align="right">计价方式：</td>
                    <td width="200px" height="32px">
                        <input id="FPriceType" name="FPriceType" class="mini-combobox" style="width:115px;" showNullItem="false" 
                            allowInput="false" align="left" value ="0" data ="comState" tabindex="1006"/> 
                    </td>
                </tr>
            </table>
        </div>
        <div id="BA10" class="setDiv">
            <table style="width: 100%; margin-top: 10px">
                <tr>
                    <td width="20px" height="32px" align="right">公众号商城是否上架</td>
                    <td width="200px" height="32px">
                        <input id="FMallFlag" name="FMallFlag" class="mini-combobox" style="width:115px;" showNullItem="false" 
                            allowInput="false" align="left" value ="0" data ="dMallFlag" tabindex="1006"/> 
                    </td>
                </tr>
                <tr>
                    <td width="80px" height="32px" align="right"></td>
                    <td width="200px" height="32px">
                        <input class="mini-button" text="同步商品到小程序商城" onclick="syncGoodsMall" />
                    </td>
                </tr>
            </table>
        </div>
        <div id="BA11" class="setDiv">
            <table style="width: 100%; margin-top: 10px">
                <tr>
                    <td width="80px" height="32px" align="right"></td>
                    <td width="200px" height="32px">
                        <div id="FRequireFlag" name="FRequireFlag" class="mini-checkbox" style="margin-right: 20px" readOnly="false" 
                        checked="false" text="要货申请"></div>
                    </td>
                </tr>
            </table>
        </div>
        <div id="BA12" class="setDiv">
            <table style="width: 100%; margin-top: 10px">
                <tr>
                    <td width="80px" height="32px" align="right"></td>
                    <td width="200px" height="32px">
                        <div id="FRequireStop" name="FRequireStop" class="mini-checkbox" style="margin-right: 20px" readOnly="false" 
                        checked="false" text="请货售罄"></div>
                    </td>
                </tr>
            </table>
        </div>
        <div id="BA13" class="setDiv">
            <table style="margin-top:10px;margin-left:30px">
                <tr>
                    <td width="110px" height="32px">
                        <input id="FPriceName" name="FPriceName" class="mini-combobox" style="width:110px;margin-left:0px;" showNullItem="false"
                                allowInput="false" align="center" value="0" data="comPriceName" />
                    </td>
                    <td width="10px" height="32px" align="center">=</td>
                    <td width="50px" height="32px">
                        <input id="FPriceRefer" name="FPriceRefer" class="mini-combobox" style="width:80px;margin-left:0px;" showNullItem="false"
                                allowInput="false" align="center" value="0" data="comPriceRefer" />
                    </td>
                    <td width="10px" height="32px" align="center">x</td>
                    <td width="70px" height="32px">
                        <input id="FPriceRate" name="FPriceRate" class="mini-spinner " style="width:70px;" minValue="1" maxValue="1000" value="100" TabIndex="11" showbutton="false" format="#,0.00" />%
                    </td>
                </tr>
            </table>
        </div>
    
        <div id="BA14" class="setDiv">
            <table style="width:100%;margin-top:10px">
                <tr>
                    <td width="80px" height="32px" align="right">供应商：</td>
                    <td width="200px" height="32px">
                        @Html.Partial("~/Views/Modular/LookUpSupply.cshtml")
                    </td>
                </tr>
            </table>
        </div>
    
    </div>
</div>
<script>
    var comPoolAgio = [
        { "id": "0", "text": "销售额百分比" },
        { "id": "1", "text": "毛利额百分比" },
        { "id": "2", "text": "固定提成金额" }
    ];

    var comState = [{ "id": "0", "text": "普通商品" },
                       { "id": "1", "text": "称重商品" },
                    { "id": "2", "text": "计件商品" }]

    var rebateType = [{ "id": "0", "text": "按金额" }, { "id": "1", "text": "按百分比" }];

    var dMallFlag = [{ "id": "0", "text": "不上架" }, { "id": "1", "text": "上架" }];

    var comPointType = [{ "id": "0", "text": "分(固定积分)" },
                   { "id": "1", "text": "%(销售额百分比)" }]

    var comPriceName = [{ "id": "0", "text": "电商价" }, { "id": "1", "text": "批发价" },
               { "id": "2", "text": "会员价" }]

    var comPriceRefer = [{ "id": "0", "text": "零售价" },
           { "id": "1", "text": "进货价" }]

    mini.parse(); 
    var grid = mini.get("datagrid1");
    var Data;

    function FormShown() {
        var data = [
            { id: 1, text: '商品提成' }, { id: 2, text: '商品分类' },
            { id: 4, text: '积分设置' }, { id: 5, text: '机构设置' }, { id: 6, text: '商品品牌' },
            { id: 7, text: '最低折扣' }, { id: 8, text: '分销返利' }, { id: 9, text: '计价方式' },
            { id: 10, text: '电商上架' }, { id: 11, text: '要货申请' }, { id: 12, text: '请货售罄' },
            { id: 13, text: '价格设置' }, { id: 14, text: '供应商设置' }
        ];
        grid.setData(data);
        grid.setSelected(data[0]);
    }

    function SetInfoData(data) {
        Data = data;
    }

    function SelectionChanged() {
        $(".fit div").hide();
        var row = grid.getSelected();
        $("#BA" + row.id).show();
    }
    
    function saveas() {
        var row = grid.getSelected();
        switch (row.id) {
            case 1: save1();
                break;
            case 2:
                save2();
                break;
            case 4:
                save4();
                break;
            case 5:
                save5();
                break;
            case 6:
                save6();
                break;
            case 7:
                save7();
                break;
            case 8:
                save8();
                break;
            case 9:
                save9();
                break;
            case 10:
                save10();
                break;
            case 11:
                save11();
                break;
            case 12:
                save12();
                break;
            case 13:
                save13();
                break;
            case 14:
                save14();
                break;
        }
    }

    function save1() {        
        if (mini.getbyName("FRebateID").getValue()+'' == '') {
            mini.alert('未选择提成类型');
            return;
        }
        var row = grid.getSelected();
        var json = '[{"rows":"' + Data + '","project":' + row.id + ',';
        json += '"value":"' + mini.getbyName("FRebateAmt").getValue() + '",'
        json += '"type":"' + mini.getbyName("FRebateID").getValue() + '",'
        json += '"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        Save(json);
    }
    function save2() {
        if (mini.getbyName("FClassNumber").getValue() == '') {
            mini.alert('未选择分类');
            return;
        }
        var row = grid.getSelected();
        var json = '[{"rows":"' + Data + '","project":' + row.id + ',';
        json += '"value":"' + mini.getbyName("FClassNumber").getValue() + '",'
        json += '"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        Save(json);
    }
    function save4() {
        var row = grid.getSelected();
        var json = '[{"rows":"' + Data + '","project":' + row.id + ',';
        json += '"value":"' + mini.getbyName("FPoint").getValue() + '",'
        json += '"type":"' + mini.getbyName("FPointType").getValue() + '",'
        json += '"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        Save(json);
    }
    function save5() {
        if (mini.getbyName("FPriceBookID").getValue()+'' == '') {
            mini.alert('未选择组织机构');
            return;
        }
        var row = grid.getSelected();
        var json = '[{"rows":"' + Data + '","project":' + row.id + ',';
        json += '"value":"' + mini.getbyName("FPriceBookID").getValue() + '",'
        json += '"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        Save(json);
    }
    function save6() {
        if (mini.getbyName("FBrandItemID").getValue()+'' == '') {
            mini.alert('未选择品牌');
            return;
        }
        var row = grid.getSelected();
        var json = '[{"rows":"' + Data + '","project":' + row.id + ',';
        json += '"value":"' + mini.getbyName("FBrandItemID").getValue() + '",'
        json += '"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        Save(json);
    }
    function save7() {
        var row = grid.getSelected();
        var json = '[{"rows":"' + Data + '","project":' + row.id + ',';
        json += '"value":"' + mini.getbyName("FLowestDis").getValue() + '",'
        json += '"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        Save(json);
    }
    function save8() {
        if (mini.getbyName("rebateType").getValue() + '' == '') {
            mini.alert('未选择返利类型');
            return;
        }
        var row = grid.getSelected();
        var json = '[{"rows":"' + Data + '","project":' + row.id + ',';
        json += '"value":"' + mini.getbyName("rebateValue").getValue() + '",'
        json += '"type":"' + mini.getbyName("rebateType").getValue() + '",'
        json += '"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        Save(json);
    }
    function save9() {
        var row = grid.getSelected();
        var json = '[{"rows":"' + Data + '","project":' + row.id + ',';
        json += '"value":"' + mini.getbyName("FPriceType").getValue() + '",'
        json += '"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        Save(json);
    }

    function save10() {
        var row = grid.getSelected();
        var json = '[{"rows":"' + Data + '","project":' + row.id + ',';
        json += '"value":"' + mini.getbyName("FMallFlag").getValue() + '",'
        json += '"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        Save(json);
    }

    function save11() {
        var row = grid.getSelected();
        var json = '[{"rows":"' + Data + '","project":' + row.id + ',';
        json += '"value":"' + mini.getbyName("FRequireFlag").getValue() + '",'
        json += '"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        Save(json);
    }
    function save12() {
        var row = grid.getSelected();
        var json = '[{"rows":"' + Data + '","project":' + row.id + ',';
        json += '"value":"' + mini.getbyName("FRequireStop").getValue() + '",'
        json += '"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        Save(json);
    }
    function save13() {
        var row = grid.getSelected();
        var json = '[{"rows":"' + Data + '","project":' + row.id + ',';
        json += '"value":' + mini.getbyName("FPriceRate").getValue() + ','
        json += '"type":"' + mini.getbyName("FPriceName").getValue() + '",'
        json += '"refer":"' + mini.getbyName("FPriceRefer").getValue() + '",'
        json += '"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        Save(json); 
    }
    function save14() {
        if (mini.getbyName("FSupplyItemID").getValue() + '' == '') {
            mini.alert('未选择供应商');
            return;
        }
        var row = grid.getSelected();
        var json = '[{"rows":"' + Data + '","project":' + row.id + ',';
        json += '"value":"' + mini.getbyName("FSupplyItemID").getValue() + '",'
        json += '"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        Save(json);
    }
    function Save(json) {
        $.post('../Goods/SaveBatch', { mjson: json }, function(data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 }, function() {
                    mini.alert("保存完成");
                });
            } else {
                mini.alert("保存失败，" + ret.error);
            }
        });
    }


    function syncGoodsMall() {
        mini.confirm("确定要同步商品资料到电商平台吗？", "提示",
            function (action) {
                if (action == "ok") {
                    setSyncGoodsMall();
                }
            }
       );
    }

    function setSyncGoodsMall() {
        $.post('../Goods/SyncGoodsMall', { mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.alert("同步完成");
            } else {
                mini.alert("同步失败，" + ret.error);
            }
        });
    }

</script>
